<?php

require_once 'Base.php';

class SellerModel extends Base {
	
	public function getList($where,$lat='32.386021',$lng='119.416639'){
		
		
		
		//$where['id = ?'] = 1;
		//if($where) $this->where($where);
		
		//$limit = "0,1";
		if($limit) $this->limit($limit);
		
		$sellers=$this->_db->fetchAll("select * from shop_seller where $where ");
		
		//print_r();
		foreach ($sellers as &$val){
			$point_arr=explode(",", $val['point']);
			$lat2=$point_arr[1];
			$lng2=$point_arr[0];
			$distance=$this->GetDistance($lat,$lng,$lat2,$lng2);
			$val['distance']=$distance.'公里';
		}
		
		
		return $sellers;
		//return $this->select();
	}
	
	//$longitude1 = 113.330405; $latitude1 = 23.147255;
	
        //获取2点之间的距离
		function GetDistance($lat1, $lng1, $lat2, $lng2){
			//echo $lat1.'|'. $lng1.'|'. $lat2.'|'. $lng2.'<br/>'; 
			define('PI',3.1415926535898);
			define('EARTH_RADIUS',6378.137);
		  $radLat1 = $lat1 * (PI / 180);
		  $radLat2 = $lat2 * (PI / 180);
		  $a = $radLat1 - $radLat2;
		  $b = ($lng1 * (PI / 180)) - ($lng2 * (PI / 180));
		  $s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)));
		  $s = $s * EARTH_RADIUS;
		  $s = round($s * 10000) / 10000;
		  return $s;
		}
	
	
	
	public function getone($where){
	
		//print_r($where);
	    $this->where($where);
		return $this->fetch();
		 //print_r($smsCodeend); die();
	}
}
